package com.noodles.mall.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.noodles.mall.entity.City;
import com.noodles.mall.service.CityService;
import com.noodles.mall.web.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/** 城市 **/
@RestController
@RequestMapping("/city")
public class CityController {
    @Autowired
    private CityService cityService;

    /**
     * 根据 上级地区id 与 类型 查找城市
     * @param type
     * @param parentId
     * @return
     */
    @RequestMapping("/findList/{type}/{parentId}")
    public JsonResult findListByTypeAndParentId(@PathVariable(value = "type") Integer type,
                                                @PathVariable(value = "parentId") Integer parentId) {
        System.out.println("UserCityController: selectCity");
        System.out.println("type: "+type);
        System.out.println("parentId: "+parentId);
        List<City> cityList = cityService.list(new QueryWrapper<City>().lambda().eq(City::getType, type).eq(City::getParentId, parentId));
        return JsonResult.success(cityList);
    }
}
